<?php

namespace app\admin\model;

use think\model\Relation;

class ToursCounsel extends Relation {

       protected $link = array(
	    'tours' => array(
		'mapping_type' => BELONGS_TO,
		'class_name' => 'Tours',
		'foreign_key' => 'tours_id',
		'mapping_fields' => 'title,id as tours_id',
		'as_fields' => 'title,tours_id',
		'parent_key' => 'id'
	    ),
	    'member' => array(
		'mapping_type' => BELONGS_TO,
		'class_name' => 'Member',
		'foreign_key' => 'mid',
		'mapping_fields' => 'realname as username',
		'as_fields' => 'username',
		'parent_key' => 'id'
	    )
	);
       
        protected function _before_write(&$data) {
                parent::_before_write($data);                
		$data['mid'] = get_member_id();
        }

        protected function _after_select(&$resultSet, $options=array()) {
		parent::_after_select($resultSet, $options);
		foreach ($resultSet as $key => $value) {
			$resultSet[$key]['tours_url'] = U("/xianlu/" . $value['tours_id'], '', 'html', 'www');
		}
	}
        protected function _after_find(&$result, $options=array()) {
		parent::_after_find($result, $options);
		$result['tours_url'] = U("/xianlu/" . $value['tours_id'], '', 'html', 'www');
	}

}
